// @Author EthanScriptOn
// @Desc
package log_context

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_basic_components/context"
	"gitee.com/fatzeng/srf_switch_log/log_define"
)

type LogInitializationContext struct {
	*context.SrfContext
}

func GenerateLogInitializationContext() *LogInitializationContext {
	return &LogInitializationContext{
		SrfContext: context.GenerateSrfContext(),
	}
}

func (l *LogInitializationContext) SetLogProfiles(logProfiles []*log_define.LogProfile) error {
	return l.Set(LogProfiles, logProfiles)
}

func (l *LogInitializationContext) GetLogProfiles() ([]*log_define.LogProfile, error) {
	logProfilesCacheValue, err := l.Get(LogProfiles)
	if err != nil {
		return nil, err
	}
	logProfiles, ok := logProfilesCacheValue.([]*log_define.LogProfile)
	if !ok {
		return nil, fmt.Errorf("the %v found according to %s is not the []*config_define.LogProfile type", logProfiles, LogProfiles)
	}
	return logProfiles, nil
}
